package control;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.BugDAO;
import model.Bug;

public class AdicionaBugServlet extends HttpServlet {
	
	protected void service(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		
		Bug bug = new Bug();
		
		String usuario = request.getParameter("usuario");
		String id = request.getParameter("id");
		String nomeUnix = request.getParameter("nomeUnix");
		String titulo = request.getParameter("titulo");
		String prioridade = request.getParameter("prioridade");
		String descricao = request.getParameter("descricao");
		String status = request.getParameter("status");
	
		bug.setUsuario(usuario);
		bug.setId(id);
		bug.setNomeUnix(nomeUnix);
		bug.setTitulo(titulo);
		bug.setPrioridade(prioridade);
		bug.setDescricao(descricao);
		bug.setStatus(status);
	
		try{
			BugDAO dao = new BugDAO();
			dao.adiciona(bug);
			} catch (SQLException e) {
			throw new ServletException(e);
			}
			
		RequestDispatcher rd = request.getRequestDispatcher("/bugRegistrado.jsp");
		rd.forward(request,response);
		return;

		
	}
}
